﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PocketPond.Core;
using PocketPond.PondConsumer;
using System.Threading;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            ClientSettings.Username = "pocketpond";
            ClientSettings.Password = "";

            ClientSettings.AuthToken = PondRequest.getAuthtoken(ClientSettings.Username, ClientSettings.Password);


            Console.WriteLine("AuthToken: " + ClientSettings.AuthToken);

            /* Read Events
            Event[] arrEvents = PondRequest.getEventsList(ClientSettings.AuthToken);
            foreach (Event ev in arrEvents)
            {
                Console.WriteLine(ev.PublishedAt.ToString() + "\t" + ev.AuthorName + "\t" + ev.TruncatedData);
            }*/

            /* Mark all events as Read */
            Event[] arrEvents;
            List<String> lstIds = new List<string>();
            while ((arrEvents = PondRequest.getEventsList(ClientSettings.AuthToken)).Count() > 0)
            {
                foreach (Event ev in arrEvents)
                {
                    Console.WriteLine(ev.PublishedAt.ToString() + "\t" + ev.AuthorName + "\t" + ev.TruncatedData);
                    PondRequest.setEventRead(ClientSettings.AuthToken, true, new String[] { ev.EventId });
                }
                Thread.Sleep(1000);
            }

            /*Account[] arrAccounts = PondRequest.getAccountList(ClientSettings.AuthToken);

            Console.Write("Posta ai qualquer coisa: ");
            String longText = Console.ReadLine();

            String fileToken = PondRequest.uploadImage(ClientSettings.AuthToken, "d:\\pond.png");
            Console.WriteLine("Response: " + fileToken);

            foreach (Account acc in arrAccounts)
            {
                String shortText;
                if (longText.Length > 140)
                {
                    shortText = longText.Substring(0,139);
                }
                else
                {
                    shortText = longText;
                }
                if (acc.CanShortText || acc.CanLongText)
                {
                    String dummy;
                    Boolean b = PondRequest.sendPost(ClientSettings.AuthToken, acc.AccountId, shortText, longText, fileToken, out dummy);
                    Console.WriteLine("Posted to (" + acc.ServiceId + ") " + acc.Description + ": " + b);
                }
            }

            Console.WriteLine(Environment.NewLine + "DONE!");*/
            Console.ReadLine();
        }
    }
}
